const express = require('express')
const expressStatic = require('express-static')
const cookieParser = require('cookie-parser')
const cookieSession = require('cookie-session')
const bodyParser = require('body-parser')
const jade = require('jade')
const ejs = require('ejs')
const multer = require('multer')
const fs = require('fs')
const pathLib = require('path')

let server = express();
server.listen(8080)
let objMulter = multer({dest: './www/upload/'})
server.use(cookieParser('asdfasdfasdfasdfasdf'));
//post数据
// server.use(bodyParser.urlencoded({extended: false}))
server.use(objMulter.any())
//用户请求
server.post('/',function(req,res,next){
	console.log(req.files)
	let newName = req.files[0].path + pathLib.parse(req.files[0].originalname).ext
	fs.rename(req.files[0].path, newName,function(err){
		if(err){
			res.send('上传失败')
			console.log('上传失败')
		}else{
			res.send('上传成功')
			console.log('上传成功')
		}
	})
})
